package cn.com.baiwei.controller;

import cn.com.baiwei.service.impl.OrderFormServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.stereotype.Controller;

import javax.annotation.Resource;

/**
 * @author thinknovo
 * @version 1.0
 */
@Controller
@Api(value = "(支付)管理",tags = "(支付)管理接口API")
@ApiResponses({
        @ApiResponse(code=400,message="请求参数不完整或者错误"),
        @ApiResponse(code=404,message="找不到页面"),
        @ApiResponse(code=405,message="请求方式不正确，比如后台接收是post，但前端请求的是get"),
        @ApiResponse(code=406,message="页面地址和接口名冲突"),
        @ApiResponse(code=415,message="请求格式不正确，前端可能没有把请求头修改为json，也可能前端请求的json对象没有转换为字符串"),
        @ApiResponse(code=500,message="后台服务逻辑错误")
})
public class PayController {

    @Resource
    private OrderFormServiceImpl orderFormServiceImpl;
    /*@RequestMapping(value = "/pay")
    @ApiOperation(value = "通过订单id和订单金额来支付",notes = "通过订单id和订单金额来支付",httpMethod = "POST")
    protected void doPost(HttpServletRequest request, HttpServletResponse response, @RequestParam String id,@RequestParam String orderMoney) throws ServletException, IOException, AlipayApiException {
        String serverURL = "https://openapi.alipaydev.com/gateway.do";     // alipay测试支付地址   生产环境支付地址为https://openapi.alipay.com/gateway.do
        String APP_ID = "2021000117660842";                                // 创建的应用ID
        // 自己的2048应用私钥
        String mKey ="MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCopBXVfxDY9WnzGp5RFwi6g2HFrBc0aVNplK6hTJlU5EeTPZ93T/GLcFcdWD/2ceUy6swHDGv05HCVoeQNZNW0VDTngMi4m3EIa1vSoe42p1QDloKG9GTUbwWqBWIvPUdkSe3kj0XOQdlXa/sL+a87lkhQCaHha/LNm5nClN3Dg5MaMIlzXWvH1uXwr89EOWvjfd0O79E7CLqsMIxJwPExr4opVKJ3hqwZngqkcnaSDrNSejOyCo3uni8ShlKogUKERsdoS9Rh8UKPKyv11YjcvsAArNCoQQmC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C+nO2JuZigQLIIqojWGkuNii1B7FvlkNBUDm6vGCBJAoGBAKOPWOM0oMKtB52g6nCwV2xopd9ZmkSy+kpcS8tNAHdxxJh0RFvgIJ852mWMEaXkoglEWJwEYGPkkiWdoD/daQwzqZ54HQzRgLX/Z2Iui4X1ep2/fPkMG1ObeaS0DjbZJiWkiieI1JkpsXc1f6Z5XI+ldSfwk/+aeMuFTMwZ0Qpy";
        // 支付宝的公钥
        String aKey ="MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAl1Ap+a+Q3LiqegKkcvLkI5xCGzyukfcQp0x76OVFkpPIr5J5kHYNsS6sHNdHyl9H7GVYrb8WM3U84/gdTfnT1ihR+P1bUIT6yME+lr5Z4v4MY2Ks6P12fA6Ndw2EUgRT+jJhNestOFg/pkMrp8iDwZzvSuWilxsq71oSys0eEAeyn1/tT0jT9FVp/1Ch489bF7yd9o7AKKGX+5Czx7cdol/6t3ifFYhwy1MvE+mous8YJykzAz9Y8hbT8K8sZdeSSwexV6Iq5lGN4QhxL1V3hbtJcG8mXsAZhIlN8rNOaEBurD85z+xcM/+uFuMNOTTjZP6dxDwllwMfAooqoXYYjQIDAQAB";
        AlipayClient alipayClient = new DefaultAlipayClient(serverURL, APP_ID,
                mKey, "json", "UTF-8", aKey, "RSA2");      //  获得初始化的AlipayClient
        AlipayTradeWapPayRequest alipayRequest = new AlipayTradeWapPayRequest();   //  创建API对应的request
        alipayRequest.setReturnUrl("http://localhost:8080/success.html");          // 用户确认支付后，支付宝get请求returnUrl
        alipayRequest.setNotifyUrl("http://localhost:8080/payReturnServlet");      // 交易成功后，支付宝post请求notifyUrl（商户入参传入）
        *//*
            由于同步返回的不可靠性，支付结果必须以异步通知或查询接口返回为准，不能依赖同步跳转。
            商户系统接收到异步通知以后，必须通过验签（验证通知中的sign参数）来确保支付通知是由支付宝发送的。
         *//*

        *//*
             填充业务参数
                 out_trade_no   每笔订单号需要自身的唯一id，支付宝会根据此id判断是否交易
                 total_amount   这笔订单的价格
                 subject        订单商品名称
                 product_code   支付方式：QUICK_WAP_PAY 登录账号支付
             这四个参数应该从结算页面传递过来
         *//*
        // 每笔订单号需要自身的唯一id，支付宝会根据此id判断是否交易
        String out_trade_no = "DX" + System.currentTimeMillis();   // 订单号一旦支付成功，永久在此应用中不可使用
        String total_amount = orderMoney;                          // 这笔订单的价格
        String subject = id;                            // 订单商品名称
        String product_code = "QUICK_WAP_PAY";                     // 支付方式：QUICK_WAP_PAY 登录账号支付

        String bizContent = "{" +
                "\"out_trade_no\":\"" + out_trade_no + "\"," +
                "\"total_amount\":" + total_amount + "," +
                "\"subject\":\"" + subject + "\"," +
                "\"product_code\":\"" + product_code + "\"}";          // 生成支付json数据
        System.out.println("支付生成json数据 bizContent=" + bizContent);

        alipayRequest.setBizContent(bizContent);                         // 提交支付请求

        String form = alipayClient.pageExecute(alipayRequest).getBody(); // 调用SDK生成表单
        response.setContentType("text/html;charset=utf-8");
        response.getWriter().write(form);                                // 直接将完整的表单html输出到页面
        response.getWriter().flush();
        response.getWriter().close();
    }*/
}
